package study.stream.collectors的toMap方法;

import study.函数式接口.Apple;
import study.函数式接口.Fruit;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author 刘伟涛
 * @Date 2023/7/13 9:28
 **/
public class    Demo01 {
    public static void main(String[] args) {
        List<Apple> appleList = Arrays.asList(new Apple("苹果01", 12, "红"),
                new Apple("苹果02", 12, "红"),
                new Apple("苹果03", 12, "红"),
                new Apple("苹果05", 12, "绿"),
                new Apple("苹果06", 12, "绿"),
                new Apple("苹果07", 12, "绿"),
                new Apple("苹果08", 12, "蓝"));
        Map<String, Apple> collect = appleList.stream().collect(Collectors.toMap(Apple::getName, ele->ele));
        System.out.println("collect:" + collect);
        Map<String, List<Apple>> collect1 = appleList.stream().collect(Collectors.groupingBy(Fruit::getColor));
        System.out.println("collect1:" + collect1);

    }
}
